<template>
    <a-spin :spinning="viewLoading" :style="spinStyle">
        <a-space :size="20">
            <a-space>
                <span>规则名称</span>
                <a-input v-model:value="ruleData.rule_name" placeholder="请输入"></a-input>
            </a-space>
            <a-space>
                <span>自定义标识符</span>
                <a-select
                    :options="customIdentifierOptions"
                    v-model:value="ruleData.custom_identifier"
                    placeholder="请选择"
                    style="width: 110px"
                    show-search
                    :filter-option="filterOption"
                ></a-select>
            </a-space>
            <a-space>
                <span>规则类型</span>
                <a-select
                    :options="ruleOptions"
                    v-model:value="ruleData.rule_type"
                    placeholder="请选择"
                    style="width: 110px"
                    show-search
                    :filter-option="filterOption"
                ></a-select>
            </a-space>
            <a-space>
                <span>发布类型</span>
                <a-select
                    :options="publishTypeOptions"
                    v-model:value="ruleData.publish_type"
                    placeholder="请选择"
                    style="width: 200px"
                    show-search
                    :filter-option="filterOption"
                ></a-select>
            </a-space>
            <a-space>
                <span>创建者</span>
                <a-select
                    :options="userOptions"
                    v-model:value="ruleData.create_id"
                    placeholder="请选择"
                    style="width: 120px"
                    show-search
                    :filter-option="filterOption"
                ></a-select>
            </a-space>
            <slot name="back"></slot>

            <a-tooltip>
                <template #title>设置发布接口字段</template>
                <a-button type="primary" @click="openSettingPublishApiField"
                    >设置字段
                    <template #icon>
                        <SettingOutlined />
                    </template>
                </a-button>
            </a-tooltip>
            <a-button :loading="saveBtnLoading" type="primary" @click="saveRule"
                >{{ saveRuleBtnText }}
                <template #icon>
                    <SaveOutlined />
                </template>
            </a-button>
        </a-space>
        <a-divider>查询文章</a-divider>
        <EsSearchHostAndIndexComponent v-model:es-host-value="esHostValue" v-model:es-index-value="esIndexValue" />
        <EsHighLevelSearchComponent
            v-model:visible="highLevelSearchVisible"
            :mustModeMap="esSearch.mustModeMap"
            v-model:query-bool="esQuery.bool"
            :es-host="esHostValue"
            :es-index="esIndexValue"
        />
        <a-button @click="openHighLevelSearchModal" type="link">查询条件</a-button>
        <a-space>
            <a-button type="primary" style="margin: 0 10px" @click="getEsArtCount" :loading="searchBtnLoading">
                <template #icon>
                    <SearchOutlined />
                </template>
                查询
            </a-button>
            <a-typography-text code type="success"> 总数:{{ esSearch.sum }} </a-typography-text>
        </a-space>
        <a-divider>其他选项</a-divider>
        <a-row>
            <a-col style="margin-bottom: 15px">
                <a-space>
                    <div v-show="isArtPublishApiType" style="margin-right: 10px">
                        采用<a-typography-text code>fb_domain</a-typography-text
                        ><a-switch v-model:checked="isFbDomain" checked-children="开" un-checked-children="关" />
                    </div>
                    <span>日发文章数</span>
                    <a-input-number id="inputNumber" v-model:value="ruleData.day_pub_num" :min="1" />
                    <a-space v-show="isShowModuleId">
                        <span>模块ID</span>
                        <a-input-number id="inputNumber" v-model:value="ruleData.module_id" :min="0" />
                    </a-space>
                    <a-space v-show="isShowCustomAttr">
                        <i>|</i>
                        <span>自定义属性</span>
                        <a-checkbox-group v-model:value="ruleData.custom_attrs" :options="customAttrOptions" />
                    </a-space>
                </a-space>
            </a-col>
            <a-col :span="24">
                <a-space>
                    <span>栏目ID与网站域名 </span>
                    <a-textarea
                        v-model:value="AddRuleWebsiteColumnData.website"
                        style="width: 260px"
                        placeholder="输入网站PC域名 多个换行"
                        :rows="4"
                    />
                    <a-textarea
                        v-model:value="AddRuleWebsiteColumnData.column"
                        style="width: 200px"
                        :rows="4"
                        placeholder="输入栏目id 0是随机 多个栏目逗号隔开 多个换行"
                    />
                </a-space>
            </a-col>
        </a-row>
        <a-row style="width: 100%; margin-top: 20px" v-if="isArtPublishApiType">
            发布选项（不选则每天都发）
            <a-checkbox-group v-model:value="ruleData.week_option" :options="weekOptions" />
        </a-row>
        <a-row :gutter="[10, 10]" style="width: 100%; margin-top: 40px" :wrap="true" v-show="isArtPublishApiType">
            <a-col style="width: 33%">
                <a-card>
                    <a-row>
                        <a-space>
                            标题替换
                            <a-switch v-model:checked="titleReplace.status" checked-children="开" un-checked-children="关" />
                        </a-space>
                    </a-row>
                    <br />
                    <div v-show="titleReplace.status">
                        标题替换规则
                        <a-typography-text keyboard>=></a-typography-text>
                        <a-textarea
                            v-model:value="titleReplace.replace_rule"
                            placeholder="替换案例：怀孕=>代孕|怀孕=>好孕"
                            allow-clear
                            show-count
                            :rows="7"
                            style="width: 100%"
                        />
                    </div>
                </a-card>
            </a-col>
            <a-col style="width: 33%">
                <a-card>
                    <a-row>
                        <a-space>
                            内容替换
                            <a-switch v-model:checked="contentReplace.status" checked-children="开" un-checked-children="关" />
                        </a-space>
                    </a-row>
                    <div v-show="contentReplace.status" style="margin-top: 10px">
                        多个规则使用
                        <a-typography-text keyboard>|</a-typography-text>
                        分割。
                        <br />
                        <b style="font-weight: 700">示例:</b>
                        被替换词
                        <a-typography-text keyboard>=></a-typography-text>
                        替换词1
                        <a-typography-text keyboard>&</a-typography-text>
                        替换词2
                        <a-typography-text keyboard>&</a-typography-text>
                        替换词3
                        <a-typography-text keyboard>@</a-typography-text>
                        替换次数
                        <a-textarea
                            v-model:value="contentReplace.replace_rule"
                            placeholder="替换案例：怀孕=>代孕&怀孕&好孕@2"
                            allow-clear
                            show-count
                            :rows="7"
                            style="width: 100%"
                        />
                    </div>
                </a-card>
            </a-col>
            <a-col style="width: 33%">
                <a-card>
                    <a-row>
                        <a-space>
                            标题插入关键词
                            <a-switch v-model:checked="titleInsertkwd.status" checked-children="开" un-checked-children="关" />
                        </a-space>
                    </a-row>
                    <br />
                    <div v-show="titleInsertkwd.status">
                        <KeywordMaxAndMinCount
                            v-model:max-count="titleInsertkwd.max_count"
                            v-model:min-count="titleInsertkwd.min_count"
                        />
                        <a-row style="margin-top: 10px">
                            <a-space>
                                <span>插入区域</span>
                                <a-input-number
                                    v-model:value="titleInsertkwd.region"
                                    placeholder="区域"
                                    style="width: 80px"
                                    :min="0"
                                    :max="1"
                                />
                                <span>插入概率</span>
                                <a-input-number
                                    v-model:value="titleInsertkwd.chance"
                                    style="width: 80px"
                                    placeholder="概率"
                                    :min="0"
                                    :max="100"
                                />
                                <span>分隔符</span>
                                <a-input v-model:value="titleInsertkwd.split_char" style="width: 80px" placeholder="分隔符" />
                            </a-space>
                        </a-row>
                        <a-row style="margin-top: 10px">
                            <span>标题关键词组</span>
                            <a-textarea
                                v-model:value="titleInsertkwd.keywords"
                                placeholder="多个使用 | 隔开"
                                allow-clear
                                show-count
                                :rows="7"
                                style="width: 100%"
                            />
                        </a-row>
                    </div>
                </a-card>
            </a-col>
            <a-col style="width: 50%">
                <a-card>
                    <a-row>
                        <a-space>
                            头部插入关键词
                            <a-switch v-model:checked="headInsertKwd.status" checked-children="开" un-checked-children="关" />
                        </a-space>
                    </a-row>
                    <div v-show="headInsertKwd.status">
                        <br />
                        <KeywordMaxAndMinCount
                            v-model:max-count="headInsertKwd.max_count"
                            v-model:min-count="headInsertKwd.min_count"
                        />
                        <a-row style="margin-top: 10px">
                            <span>标题关键词组</span>
                            <a-textarea
                                v-model:value="headInsertKwd.keywords"
                                placeholder="多个使用 | 隔开"
                                allow-clear
                                show-count
                                :rows="7"
                                style="width: 100%"
                            />
                        </a-row>
                    </div>
                </a-card>
            </a-col>
            <a-col style="width: 50%">
                <a-card>
                    <a-row>
                        <a-space>
                            中部插入关键词
                            <a-switch v-model:checked="centerInsertKwd.status" checked-children="开" un-checked-children="关" />
                        </a-space>
                    </a-row>
                    <div v-show="centerInsertKwd.status">
                        <br />
                        <KeywordMaxAndMinCount
                            v-model:max-count="centerInsertKwd.max_count"
                            v-model:min-count="centerInsertKwd.min_count"
                        />
                        <a-row style="margin-top: 10px">
                            <span>标签定位符</span>
                            <a-input v-model:value="centerInsertKwd.position_char" placeholder="</p>" style="width: 100%" />
                        </a-row>
                        <a-row style="margin-top: 10px">
                            <span>标题关键词组</span>
                            <a-textarea
                                v-model:value="centerInsertKwd.keywords"
                                placeholder="多个使用 | 隔开"
                                allow-clear
                                show-count
                                :rows="7"
                                style="width: 100%"
                            />
                        </a-row>
                    </div>
                </a-card>
            </a-col>
            <a-col style="width: 50%">
                <a-card>
                    <a-row>
                        <a-space>
                            底部插入关键词
                            <a-switch v-model:checked="footerInsertKwd.status" checked-children="开" un-checked-children="关" />
                        </a-space>
                    </a-row>
                    <div v-show="footerInsertKwd.status">
                        <br />
                        <KeywordMaxAndMinCount
                            v-model:max-count="footerInsertKwd.max_count"
                            v-model:min-count="footerInsertKwd.min_count"
                        />
                        <a-row style="margin-top: 10px">
                            <span>标题关键词组</span>
                            <a-textarea
                                v-model:value="footerInsertKwd.keywords"
                                placeholder="多个使用 | 隔开"
                                allow-clear
                                show-count
                                :rows="7"
                                style="width: 100%"
                            />
                        </a-row>
                    </div>
                </a-card>
            </a-col>
            <a-col style="width: 50%">
                <a-card>
                    <a-row>
                        <a-space>
                            插入图片
                            <a-switch v-model:checked="insertImg.status" checked-children="开" un-checked-children="关" />
                        </a-space>
                    </a-row>
                    <div v-show="insertImg.status">
                        <a-space style="margin: 10px 0"> </a-space>
                        <ImgDirectorySelect
                            v-model:dir="insertImg.directory"
                            v-model:searchBody="insertImg.esBody"
                            v-model:tags="insertImg.tags"
                        />
                        <br />
                        <KeywordMaxAndMinCount v-model:max-count="insertImg.max_count" v-model:min-count="insertImg.min_count" />
                    </div>
                </a-card>
            </a-col>
            <a-col style="width: 100%">
                <a-card>
                    <a-row>
                        <a-space>
                            插入组合图片
                            <a-switch v-model:checked="insertZuheImg.status" checked-children="开" un-checked-children="关" />
                        </a-space>
                    </a-row>
                    <div v-show="insertZuheImg.status">
                        <br />
                        <a-space :size="10" direction="vertical">
                            <a-row>
                                <KeywordMaxAndMinCount
                                    v-model:max-count="insertZuheImg.max_count"
                                    v-model:min-count="insertZuheImg.min_count"
                                    :type="1"
                                />
                                <a-space :size="12">
                                    <a-space style="margin-left: 10px">
                                        图片位置
                                        <a-input-number id="inputNumber" v-model:value="insertZuheImg.img_position" />
                                    </a-space>
                                    <a-space>
                                        文本位置
                                        <a-input-number id="inputNumber" v-model:value="insertZuheImg.text_position" />
                                    </a-space>
                                </a-space>
                                <a-button type="link" @click="showImg">查看图片</a-button>
                            </a-row>
                            <a-row :gutter="10">
                                <a-col>
                                    <InputNumberWidthAndHeight
                                        v-model:height="insertZuheImg.canvas_size.height"
                                        v-model:width="insertZuheImg.canvas_size.width"
                                    />
                                </a-col>
                                <a-col>
                                    <InputNumberWidthAndHeight
                                        v-model:height="insertZuheImg.logo_size.height"
                                        v-model:width="insertZuheImg.logo_size.width"
                                        :type="1"
                                    />
                                </a-col>
                                <a-col :span="6">
                                    <a-row type="flex" align="middle">
                                        <a-col> logo透明度 </a-col>
                                        <a-col :span="12">
                                            <a-slider v-model:value="insertZuheImg.pellucidity" :min="0" :max="1" :step="0.01" />
                                        </a-col>
                                    </a-row>
                                </a-col>
                            </a-row>
                            <a-row :gutter="10">
                                <a-col>
                                    <a-space :size="20">
                                        文本
                                        <a-input placeholder="输入文本" v-model:value="insertZuheImg.text"></a-input>
                                    </a-space>
                                </a-col>
                                <a-col>
                                    <a-space>
                                        字体大小
                                        <a-input-number id="inputNumber" v-model:value="insertZuheImg.font_size" :max="30" />
                                    </a-space>
                                </a-col>
                                <a-col>
                                    <a-space :size="20">
                                        字体颜色
                                        <a-input type="color" style="width: 60px" v-model:value="insertZuheImg.font_color" />
                                    </a-space>
                                </a-col>
                                <a-col>
                                    <a-space :size="20">
                                        字体
                                        <a-select
                                            style="width: 120px"
                                            show-search
                                            :filter-option="filterOption"
                                            :options="fontOptions"
                                            v-model:value="insertZuheImg.font_type"
                                        ></a-select>
                                    </a-space>
                                </a-col>
                                <a-col>
                                    <a-space :size="20">
                                        背景
                                        <a-select
                                            style="width: 100px"
                                            :options="imgDirOptions"
                                            v-model:value="insertZuheImg.background"
                                            show-search
                                            :filter-option="filterOption"
                                        ></a-select>
                                    </a-space>
                                </a-col>
                                <a-col>
                                    <a-space :size="20">
                                        logo
                                        <a-select
                                            style="width: 100px"
                                            :options="logoDirOptions"
                                            v-model:value="insertZuheImg.logo"
                                            show-search
                                            :filter-option="filterOption"
                                        ></a-select>
                                    </a-space>
                                </a-col>
                            </a-row>
                        </a-space>
                    </div>
                </a-card>
            </a-col>
            <a-col style="width: 50%">
                <a-card>
                    <KeywordMaxAndMinCount v-model:max-count="cmsKeywords.max_count" v-model:min-count="cmsKeywords.min_count" />
                    <a-row style="margin-top: 10px">
                        <b>cms关键词组</b>
                        <a-textarea
                            v-model:value="cmsKeywords.keywords"
                            placeholder="多个使用 | 隔开"
                            allow-clear
                            show-count
                            :rows="7"
                            style="width: 100%"
                        />
                    </a-row>
                </a-card>
            </a-col>
            <a-col style="width: 50%">
                <a-card>
                    <KeywordMaxAndMinCount v-model:max-count="tagWeywords.max_count" v-model:min-count="tagWeywords.min_count" />
                    <a-row style="margin-top: 10px">
                        <b>tag关键词组</b>
                        <a-textarea
                            v-model:value="tagWeywords.keywords"
                            placeholder="多个使用 | 隔开"
                            allow-clear
                            show-count
                            :rows="7"
                            style="width: 100%"
                        />
                    </a-row>
                </a-card>
            </a-col>
        </a-row>
    </a-spin>
    <SettingPublishApiField
        v-model:visible="isShowSettingPublishApiField"
        :esHost="esHostValue"
        :esIndex="esIndexValue"
        :publishApiFieldData="publishApiFieldData"
        v-model:fieldData="publishFieldData"
    />
</template>

<script lang="ts" setup>
    import { SaveOutlined, SettingOutlined, SearchOutlined } from "@ant-design/icons-vue";
    import { message } from "ant-design-vue";
    import type { TableDataItme } from "@/hooks/useArticlePublishRule";
    import { useCommonAsyncOptions, useCommonStaticOptions } from "@/hooks/useEsArticleCommon";
    import { cloneDeep, get } from "@/utils/lodash";

    import { useRequireField } from "@/hooks/useEsArticleRule";
    import { ImgDirectorySelect } from "@/components/home/tsx/commonComponents";
    import { useVModels } from "@vueuse/core";
    import {
        KeywordMaxAndMinCount,
        InputNumberWidthAndHeight,
        SettingPublishApiField
    } from "@/pages/home/esArticle/tsx/publishComponents";
    import EsHighLevelSearchComponent from "@/tsx/esCommonSearch/EsHighLevelSearch";
    import EsSearchHostAndIndexComponent from "@/tsx/esCommonSearch/EsSearchHostAndIndex";
    import { useSpinLoadingState } from "@/hooks/useCommon";
    import { getEsArtCountApi } from "@/api/esArticle";
    defineOptions({
        name: "AddPublishRule"
    });
    const { spinStyle, viewLoading } = useSpinLoadingState();
    const emits = defineEmits<{
        (event: "update:rule"): void;
        (event: "save:rule", ruleObj: PostPublishRuleParams | TableDataItme): void;
    }>();
    const props = defineProps<{
        saveRuleBtnText: string;
        type: "update" | "add";
        rule: PostPublishRuleParams | TableDataItme;
    }>();

    const { rule: ruleData } = useVModels(props, emits);
    const {
        artWycOptions,
        ruleOptions,
        customIdentifierOptions,
        userOptions,
        fontOptions,
        imgDirOptions,
        logoDirOptions,
        publishTypeOptions
    } = useCommonAsyncOptions();
    const { filterOption, customAttrOptions,weekOptions } = useCommonStaticOptions();
    // es服务器
    const esHostValue = ref("http://192.168.1.92:9200");
    // 文章索引
    const esIndexValue = ref("");
    // 设置发布接口字段 组件相关状态
    const isShowSettingPublishApiField = ref(false);
    // 显示组件
    const openSettingPublishApiField = () => {
        if (!esHostValue.value || !esIndexValue.value) {
            message.error("请填写服务器和索引!");
            return;
        }
        isShowSettingPublishApiField.value = true;
    };
    const publishApiFieldData = computed(() => {
        return (publishTypeOptions.value.find((item) => item.value === ruleData.value.publish_type) || { field_data: [] })
            .field_data;
    });
    const searchBtnLoading = ref(false);
    // 控制高级搜索的对话框隐藏显示
    const highLevelSearchVisible = ref(false);
    // 打开高级搜索对话框输入其他条件
    const openHighLevelSearchModal = () => {
        if (!esHostValue.value || !esIndexValue.value) {
            message.error("请输入索引或选择EsHost");
            return;
        }
        highLevelSearchVisible.value = true;
    };
    // 添加规则的栏目信息
    const AddRuleWebsiteColumnData = reactive({
        website: "",
        column: ""
    });
    // 发布接口类型 为 1普通文章 2多字段
    const isArtPublishApiType = computed(
        () => publishTypeOptions.value.find((item) => item.value === ruleData.value.publish_type)?.api_type === 1
    );
    const {
        title_replace: titleReplace,
        content_replace: contentReplace,
        title_insert_kwd: titleInsertkwd,
        head_insert_kwd: headInsertKwd,
        cms_keywords: cmsKeywords,
        tag_keywords: tagWeywords,
        insert_zuhe_img: insertZuheImg,
        insert_img: insertImg,
        footer_insert_kwd: footerInsertKwd,
        center_insert_kwd: centerInsertKwd,
        es_search: esSearch,
        publish_field_data: publishFieldData,
    } = toRefs(ruleData.value);
    const [requireFields, otherRequireFields] = useRequireField();

    // 自定义属性的checkbox是否显示
    const isShowCustomAttr = computed(() => [2, 4, 5].includes(ruleData.value.publish_type));
    const isShowModuleId = computed(() => ruleData.value.publish_type === 3);
    const saveBtnLoading = ref(false);
    // 保存规则
    const saveRule = () => {
        const newRuleObj = cloneDeep(ruleData.value);
        const { custom_attrs } = newRuleObj;
        // 处理 column_ids 字段
        newRuleObj.column_ids = {};
        const columnRows = AddRuleWebsiteColumnData.column.split("\n").filter(Boolean);
        const websiteRows = AddRuleWebsiteColumnData.website
            .split("\n")
            .filter(Boolean)
            .map((i) => i.trim());
        if (websiteRows.length !== columnRows.length) {
            message.error("网站数与栏目Id数不匹配!");
            return;
        }
        columnRows.forEach((row: string, index) => {
            const ids = row
                .trim()
                .split(",")
                .filter((item) => Boolean(item) == false || !isNaN(Number(item)))
                .map(Number);
            // 收集column_ids参数
            // {website:ids}
            Reflect.set(newRuleObj.column_ids, websiteRows[index], ids);
        });
        // 处理自定义属性如果有其他属性,那么删除随机
        if (custom_attrs.length > 1) {
            newRuleObj.custom_attrs = custom_attrs.filter((v) => v !== "random");
        }
        newRuleObj["es_search"]["index"] = esIndexValue.value;
        newRuleObj["es_search"]["host"] = esHostValue.value;
        newRuleObj["es_search"]["body"] = { query: esQuery.value };
        // 检查字段是否为空
        for (const item of requireFields) {
            if (!get(newRuleObj,item.key)) {
                message.error(item.message);
                return;
            }
        }
        // 判断发布接口字段是否填写完整!
        for (const item of Object.values(publishFieldData.value)) {
            if (!item) {
                return message.error("请将设置字段中内容填写完整!");
            }
        }
        // 其他需要检查的字段
        for (const item of otherRequireFields) {
            const key = item.key;
            if (key.includes(".")) {
                const [firstKey, lastKey] = key.split(".");
                // @ts-ignore
                const status: boolean = newRuleObj[firstKey]["status"];
                // @ts-ignore
                if (status === true && !newRuleObj[firstKey][lastKey]) {
                    message.error(item.message);
                    return;
                }
                // @ts-ignore 将布尔类型转换为数字
                newRuleObj[firstKey]["status"] = status ? 1 : 0;
            }
        }

        newRuleObj["is_fb_domain"] = isFbDomain.value ? 1 : 0;
        // 伪原创类型
        const mustModeMap = esSearch.value.mustModeMap;
        newRuleObj["es_search"]["wyc"] = "";
        wycLoop: for (const key in mustModeMap) {
            // @ts-ignore
            for (const item of mustModeMap[key]["conditions"]) {
                const wycType = item["field"] + "-" + item["value"];
                const wycItem = artWycOptions.value.find((item) => item.value === wycType);
                if (wycItem) {
                    newRuleObj["es_search"]["wyc"] = wycItem.value as string;
                    break wycLoop;
                }
            }
        }

        emits("save:rule", newRuleObj);
    };
    // 预览图片
    const showImg = () => {
        const obj = insertZuheImg.value;
        // 画布高度宽度
        const canvasHeigth = obj["canvas_size"]["height"];
        const canvasWidth = obj["canvas_size"]["width"];
        // font_color
        const fontColor = obj["font_color"];
        // 字体大小
        const fontSize = obj["font_size"];
        // 字体类型
        const fontType = obj["font_type"];
        // 文本位置
        const textPosition = obj["text_position"];
        // logo
        const logoHeight = obj["logo_size"]["height"];
        const logoWidth = obj["logo_size"]["width"];
        const logoDir = obj["logo"];
        // imgdir
        const imgDir = obj["background"];
        // 透明度
        const opacity = obj["pellucidity"];
        // text
        const text = "test";
        // 图片位置
        const imgPosition = obj["img_position"];
        const imgUrl = `http://cximg.74g.net/api/img_${imgDir}_${canvasWidth}_${canvasHeigth}/logo_${logoDir}_${imgPosition}_${opacity}_${logoWidth}_${logoHeight}/text_${textPosition}_${fontType}_${fontSize}_${fontColor.slice(
            1
        )}/${text}/test.jpg`;
        window.open(imgUrl);
    };
    // 获取文章数量
    const getEsArtCount = () => {
        searchBtnLoading.value = true;
        getEsArtCountApi({ host: esHostValue.value, index: esIndexValue.value, query: esQuery.value })
            .then((res) => {
                esSearch.value.sum = res.data.count;
            })
            .finally(() => (searchBtnLoading.value = false));
    };
    const esQuery = ref<{ bool: EsQueryBoolType }>({ bool: { must: [], must_not: [], should: [] } });
    const isFbDomain = ref(true);
    onMounted(() => {
        // 更新查询条件
        esQuery.value = ruleData.value.es_search.body.query;
        if (!esQuery.value.bool.should) {
            esQuery.value.bool.should = [];
        }
        if (!esQuery.value.bool.must_not) {
            esQuery.value.bool.must_not = [];
        }
        isFbDomain.value = !!ruleData.value.is_fb_domain;
        esIndexValue.value = ruleData.value.es_search.index;
        if (esSearch.value.host) {
            esHostValue.value = esSearch.value.host;
        }
        if (esSearch.value.index) {
            esIndexValue.value = esSearch.value.index;
        }
        setTimeout(() => (viewLoading.value = false), 1000);
        if (props.type === "update") {
            const obj = ruleData.value.column_ids as Record<string, number[]>;
            try {
                AddRuleWebsiteColumnData.column = Object.values(obj)
                    .map((item) => item.join(","))
                    .join("\n");
                AddRuleWebsiteColumnData.website = Object.keys(obj).join("\n");
            } catch {
                message.error("栏目与网站加载错误!");
            }
        }
    });
</script>

<style scoped lang="scss"></style>
@/hooks/useArticlePublishRule
